package com.zhongyong.server.process;

import java.io.IOException;
import java.util.List;

import com.common.entity.Car;
import com.common.entity.DataPack;
import com.common.server.view.ServerMainFrame;
import com.common.server.view.ServerProcessThread;
import com.common.server.view.ServiceProcess;
import com.zhongyong.server.dao.CarDao;
import com.zhongyong.server.dao.impl.CarDaoImpl;

public class CarServiceProcess implements ServiceProcess{

	@Override
	public Object service(DataPack dataPack, ServerProcessThread serverProcessThread, ServerMainFrame serverMainFrame)
			throws IOException {
		CarDao carDao = new CarDaoImpl();
		if("addCar".equals(dataPack.getOptType())) {
			Car car = new Car();
			car = (Car) dataPack.getCon();
			int rows = carDao.saveCar(car);
			DataPack p1 = new DataPack();
			p1.setCon(rows);
			p1.setOptType(dataPack.getOptType());	
			serverProcessThread.getOos().writeObject(p1);
			serverProcessThread.getOos().flush();
			
			
		}
		else if("updateCar".equals(dataPack.getOptType())){
			Car car = new Car();
			car = (Car) dataPack.getCon();
			int rows = carDao.updateCar(car);
			DataPack p1 = new DataPack();
			p1.setCon(rows);
			p1.setOptType(dataPack.getOptType());	
			serverProcessThread.getOos().writeObject(p1);
			serverProcessThread.getOos().flush();
			
		}
		else if("getCarNum".equals(dataPack.getOptType())){
			List<Integer> carNums=carDao.getCarNum();
			DataPack p1 = new DataPack();	
			p1.setOptType(dataPack.getOptType());	
			p1.setCon(carNums);
			serverProcessThread.getOos().writeObject(carNums);
			serverProcessThread.getOos().flush();
			
		}
		return null;
	}

}
